import { getThingWithService } from '@/api/thing'
import type { TreeNodeData } from 'element-plus/es/components/tree/src/tree.type'

export function useTree() {
  const thingTreeRef = ref(null)
  const onInitTreeData = async () => {
    const res = await getThingWithService()
    return res.list
  }
  const getCheckedNodes = (leafOnly: boolean): TreeNodeData[] => {
    return thingTreeRef.value?.treeRef?.getCheckedNodes(leafOnly) || []
  }
  const onNodeExpand = async (data, node: TreeNodeData) => {
    /*const res = await getServiceListByThingId(data.id)
    console.log(111, res.list)*/
  }
  return {
    thingTreeRef,
    onInitTreeData,
    getCheckedNodes,
    onNodeExpand,
  }
}
